Starting to learn Assembly for ARMV8 with a Khadas Vim3 and Ubuntu 24.04

I'm starting to learn assembly for ARMV8(Aarch64). I've got a Khadas Vim 3 board with a Amlogic Cortex A73 processor. I have flashed the eMMC with Ubuntu 24.04 with the USB Burning Tool. To start this off I'm going to follow some tutorials and take some examples from them. I have corrected some errors so I want somewhere to keep track of the code that works.

This is from chapter 2 of Thinkingeek's tutorial

// first.s
.text

.globl main

main:
     mov w0, #2
     ret

Now to assemble it

$ aarch64-linux-gnu-as -c -o first.o first.s

and then link it

$ aarch64-linux-gnu-gcc -static -o first first.o

To run it

$ ./first
$ echo $?
$ 2 

2 is the return

Now let's try a hello world. This is from Peter Nelson's tutorial

// hello.s

.data /* Data segment: define our message string and calculate its length. */
msg:
    .ascii        "Hello, ARM64!\n"
len = . - msg

.text /* Our application's entry point. */
.globl main
main:
    /* syscall write(int fd, const void *buf, size_t count) */
    mov     x0, #1      /* fd := STDOUT_FILENO */
    ldr     x1, =msg    /* buf := msg */
    ldr     x2, =len    /* count := len */
    mov     w8, #64     /* write is syscall #64 */
    svc     #0          /* invoke syscall */

    /* syscall exit(int status) */
    mov     x0, #0      /* status := 0 */
    mov     w8, #93     /* exit is syscall #93 */
    svc     #0          /* invoke syscall */

and again to assemble it

$ aarch64-linux-gnu-as -c -o hello.o hello.s

and then link it

$ aarch64-linux-gnu-gcc -static -o hello hello.o

To run it

$ ./hello
Hello, ARM64!
$ 

That's two working examples for now. I also highly recommend Vega's ARMv8 AArch64/ARM64 Full Beginner's Assembly Tutorial

Check out some other Bands on .Bandcamp.com. Crazy Fingers (Vancouver 1991), Altogether Steve and the Mercenaries, and Hammy Ham Hands.

Proudly powered by an IDE, a Text Editor, and some Internet Searches.

2024 dispelled.ca end of file.